package zcw.com.lib_leet_code;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by 朱城委 on 2021/8/9.<br><br>
 *
 * 简单：相对名次
 */
public class Topic506 {

    public static void main(String[] args) {
        Topic506 instance = new Topic506();

        int[] array = new int[] {5,4,3,2,1};
        System.out.println(Arrays.toString(instance.findRelativeRanks(array)));

        array = new int[] {10,3,8,9,4};
        System.out.println(Arrays.toString(instance.findRelativeRanks(array)));
    }

    public String[] findRelativeRanks(int[] score) {
        String[] result = new String[score.length];
        Map<Integer, Integer> map = new HashMap<>();
        for(int i = 0; i < score.length; i++) {
            map.put(score[i], i);
        }

        Arrays.sort(score);

        for(int i = score.length - 1; i >= 0; i--) {
            if(i == score.length - 1) {
                result[map.get(score[i])] = "Gold Medal";
            }
            else if(i == score.length - 2) {
                result[map.get(score[i])] = "Silver Medal";
            }
            else if(i == score.length - 3) {
                result[map.get(score[i])] = "Bronze Medal";
            }
            else {
                result[map.get(score[i])] = String.valueOf(score.length - i);
            }
        }
        return result;
    }
}
